package com.hankol.feature_wine_meal.viewmodel

import android.webkit.WebSettings
import com.baselibrary.activity.BaseActivity
import com.baselibrary.base.mvvm.BaseViewModel
import com.baselibrary.bean.ShareItemBean
import com.baselibrary.view.share.SharePopupWindow
import com.baselibrary.utils.ShareManager
import com.hankol.feature_wine_meal.api.WineMealHelp

/**
 * @author: 关忆北、
 * @date: 2022/7/6
 * @Des：
 */
class WineMealWebViewModel : BaseViewModel() {

    fun initWeb(webSettings: WebSettings) {
        webSettings.javaScriptEnabled = true;
        webSettings.allowFileAccess = true;
        webSettings.allowFileAccessFromFileURLs = true;
        webSettings.allowUniversalAccessFromFileURLs = true;
        webSettings.javaScriptCanOpenWindowsAutomatically = true;
        webSettings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
        webSettings.defaultZoom = WebSettings.ZoomDensity.CLOSE;
        webSettings.loadWithOverviewMode = true;//和setUseWideViewPort(true)一起解决网页自适应问题
        webSettings.setAppCacheEnabled(true);//是否使用缓存
        webSettings.domStorageEnabled = true;//DOM Storage
        webSettings.cacheMode = WebSettings.LOAD_DEFAULT;
        webSettings.databaseEnabled = true;
        webSettings.useWideViewPort = true;
        webSettings.textZoom = 100
    }

    fun showShare(activity: BaseActivity, wineMealHelp: WineMealHelp): SharePopupWindow? {
        val title = "中国下酒菜介绍"
        val des = "四类下酒菜，让酒增香，让饭局高级有风度"
        val shareItem = ShareManager.showSharePopWindow(activity, wineMealHelp.getIntroduceUrl(), "", title, des, object : SharePopupWindow.OnShareClickListener {
            override fun onShareClick(type: Int) {}
            override fun onShareFriendClick(bean: ShareItemBean) {}
        })
        shareItem?.setShareItem(true)
        return shareItem
    }


}